package com.zara.store.ws;

import java.net.MalformedURLException;
import java.rmi.RemoteException;

import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

import com.zara.store.common.EnvtHelper;
import com.zara.store.common.EnvtVO;
import com.zara.store.common.IntegrationTransformer;

public class EnvtWsClient {
	public static void main(String[] args) throws Exception {
		String envt = "<envt>"
					+ "<fechaalta class=\"sql-timestamp\">2008-11-27 00:47:16.062</fechaalta>"
					+ "<items>" 
					+ "<envtitem>" + "<referencia>3</referencia>"
					+ "<cantidad>10</cantidad>" + "</envtitem>" 
					+ "</items>" 
					+ "</envt>";
		
//		EnvtVO envtVO = new EnvtHelper().createEnvtFromXml(new IntegrationTransformer().transform(envt));
//		System.out.println(envtVO);
		new EnvtWsClient().testEnvt(envt);
	}

	public boolean testEnvt(String xml) throws ServiceException,
			MalformedURLException, RemoteException {
		Service service = new Service();
		Call call = (Call) service.createCall();
		call.setTargetEndpointAddress("http://localhost:8080/axis/services/RecibirEnvioATienda");
		call.addParameter("xml", XMLType.XSD_STRING, ParameterMode.IN);
		call.setReturnType(XMLType.XSD_INT);
		call.setOperationName("recibirEnvioATienda");
		Object ret = call.invoke(new Object[] { xml });
		return ("1".equals(ret));
	}

}